#include"util.hpp"
#include<iostream>
#include<string>
#include<vector>
#include"hot.hpp"
#include"config.hpp"
#include"data.hpp"
//using namespace cloud;
void FileUtilTest(std::string filename)
{
/*	cloud::FileUtil fu(filename);
	std::cout<<fu.filesize()<<std::endl;
	std::cout<<fu.LastAtime()<<std::endl;
	std::cout<<fu.LastMtime()<<std::endl;
*/
/*
	cloud::FileUtil fu(filename);
	std::string body;
	fu.GetContent(body);
	std::cout<<body.c_str();
	cloud::FileUtil fu2("./hello.txt");
	fu2.SetContent(body);
*/

/*	cloud::FileUtil fu("./hello.txt");
	fu.Compress("./hello.zip");

	std::string packname=filename+".lz";
	cloud:: FileUtil fu(filename);
	fu.Compress(packname);
	cloud::FileUtil pfu(packname);
	pfu.UnCompress("./hello(2).txt");*/
/*
	cloud::FileUtil fu(filename);
	fu.CreateDirectory();
	std::vector<std::string> arr;
	fu.ScanDirectory(arr);
	for(auto p:arr)
	{
		std::cout<<p<<std::endl;
	}*/

	
	return ;
}
void testJsonUtil()
{		
	const char* name="小明";
	int age=19;
	float score[]={85,88.5,99};
	Json::Value val;
	val["姓名"]=name;
	val["年龄"]=age;
	val["成绩"].append(score[0]);
	val["成绩"].append(score[1]);
	val["成绩"].append(score[2]);
	std::string json_str;
	cloud::JsonUtil::Serialize(val,&json_str);
	std::cout<<json_str<<std::endl;
	
	cloud::JsonUtil::UnSerialize(json_str,&val);
	std::cout<<val["姓名"].asString()<<std::endl;
	std::cout<<val["年龄"].asInt()<<std::endl;
	for(int i=0;i<val["成绩"].size();i++)
	{
		std::cout<<val["成绩"][i]<<std::endl;	
	}
	return ;

}
void testconfig()
{
	cloud::Config* cp=cloud::Config::GetInstance();
	std::cout<<cp->GetHotTime()<<std::endl;

	std::cout<<cp->GetServerIP()<<std::endl;
	std::cout<<cp->GetServerPort()<<std::endl;
	std::cout<<cp->GetDownloapPrefix()<<std::endl;
	std::cout<<cp->GetPackFileSuffix()<<std::endl;
	std::cout<<cp->GetPackDir()<<std::endl;
	std::cout<<cp->GetBackDir()<<std::endl;
	std::cout<<cp->GetBackupFile()<<std::endl;


}
void datatest(const std::string & filename)
{
	/*
	cloud::BackInfo bi;
	bi.NewBackInfo(realpath);
	cloud::DataManager dm;
	dm.Insert(bi);
	
	cloud::BackInfo tem;
	dm.GetOneByUrl("/downloap/bundle.h",&tem);	
	std::cout<<"-----------insert getbyurl----------"<<std::endl;
	std::cout<<tem._fsize<<std::endl;
	std::cout<<tem._atime<<std::endl;
	std::cout<<tem._mtime<<std::endl;
	std::cout<<tem._real_path<<std::endl;
	std::cout<<tem._pack_path<<std::endl;
	std::cout<<tem._url<<std::endl;
	bi._pack_flag=true;
	dm.UpData(bi);	
	dm.GetOneByUrl("/downloap/bundle.h",&tem);	
	std::cout<<tem._pack_flag<<std::endl;
	std::vector<cloud::BackInfo> arry;
	dm.GetAll(&arry);
	dm.Storage();	
	*/
	/*
	DataManager dm;
	BackInfo bi;
	dm.GetOneByUrl("/downloap/bundle.h",&bi);
	std::cout<<bi._fsize<<std::endl;
	std::cout<<bi._atime<<std::endl;
	std::cout<<bi._mtime<<std::endl;
	std::cout<<bi._real_path<<std::endl;
	std::cout<<bi._pack_path<<std::endl;
	std::cout<<bi._url<<std::endl;
	*/
/*
	BackInfo  bi;
	bi.NewBackInfo(filename);
	DataManager dm;
	dm.Insert(bi);
	dm.Storage();


	DataManager dm2;
	std::vector<BackInfo> arry;
	dm2.GetAll(&arry);
	for(auto a:arry){			
		std::cout<<a._fsize<<std::endl;
		std::cout<<a._atime<<std::endl;
		std::cout<<a._mtime<<std::endl;
		std::cout<<a._real_path<<std::endl;
		std::cout<<a._pack_path<<std::endl;
		std::cout<<a._url<<std::endl;
	}
*/		

}

cloud::DataManager * _data;
void HotTest(){
	_data=new cloud::DataManager();
	cloud::HotManager hot;
	hot.RunModule();
	
	
	return ;
}
int main(int argc,char * argv[])
{
/*	FileUtilTest(argv[1]);
	testJsonUtil();*/
//	testconfig();
//	datatest(argv[1]);
	HotTest();
	return 0;
}
